package com.europe.business.europebusiness.ui.adapter;

import android.app.Activity;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.europe.business.europebusiness.R;
import com.europe.business.europebusiness.ui.bean.Company;

import java.util.List;

public class RecomandCompanyAdapter extends RecyclerView.Adapter<RecomandCompanyAdapter.RecomandCompanyViewHolder> {
    private Context mContext;
    private List<Company> mData;

    public RecomandCompanyAdapter(Context mContext, List<Company> mData) {
        this.mContext = mContext;
        this.mData = mData;
    }

    @NonNull
    @Override
    public RecomandCompanyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        int width = (int) (((Activity) mContext).getWindowManager().getDefaultDisplay().getWidth() * 0.6);
        int height = (int) (width / 2);
        View itemView = LayoutInflater.from(mContext).inflate(R.layout.item_recomand_company, viewGroup, false);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(width, height);
        layoutParams.setMargins(20, 20, 20, 20);
        RecomandCompanyViewHolder recomandCompanyViewHolder = new RecomandCompanyViewHolder(itemView);
        return recomandCompanyViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecomandCompanyViewHolder recomandCompanyViewHolder, int i) {

        recomandCompanyViewHolder.companyName.setText(mData.get(i).getCompanyName());
        recomandCompanyViewHolder.companyType.setText(mData.get(i).getType());
        recomandCompanyViewHolder.companyCountryCity.setText(mData.get(i).getCountry() + "-" + mData.get(i).getCity());
    }


    @Override
    public int getItemCount() {
        return mData.size();
    }

    class RecomandCompanyViewHolder extends RecyclerView.ViewHolder {
        public ImageView companyLogo;
        public TextView companyName;
        public TextView companyType;
        public TextView companyCountryCity;

        public RecomandCompanyViewHolder(@NonNull View itemView) {
            super(itemView);
            companyLogo = itemView.findViewById(R.id.company_logo);
            companyName = itemView.findViewById(R.id.company_name);
            companyType = itemView.findViewById(R.id.company_type);
            companyCountryCity = itemView.findViewById(R.id.company_country_city);
        }
    }
}